package com.zh.ssmshirofreemarker.controller;

import com.zh.ssmshirofreemarker.service.IPermissionService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.apache.shiro.authz.annotation.RequiresUser;
import org.apache.shiro.session.Session;
import org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO;
import org.apache.shiro.session.mgt.eis.SessionDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class IndexController {

    @Autowired
    IPermissionService permissionService;

    @Autowired
    SessionDAO sessionDAO;

    @RequiresPermissions("index:view")
    @RequestMapping("/")
    public String index(Map<String,Object> map,HttpServletRequest request){
        request.getSession().setAttribute("username",SecurityUtils.getSubject().getPrincipal());
        List<Map<String,Object>> list =  permissionService.getAllMenu();
        map.put("menus",list);
        System.out.println(list);
        return "index";
    }

    @RequestMapping("/index_v1")
    public String indexV1(Map<String,Object> map){
        return "index_v1";
    }


}
